<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

loadPage("head.php");
?>
<h1>Список пользователей</h1><br />
<?php
	if ($user->getUserId() == 1){
		?><div class='floating'><a href='users/add'>Добавить пользователя</a></div><?php
	}
?><table cellpadding='0' cellspacing='0' class='list'>
	<tr class='table_header'>
		<td width='50px'>ID</td>
		<td width='150px'>Логин</td>
		<td width='120px'>Тип</td>
		<td width='110px'>Последний IP</td>
		<td width='130px'>Последний заход</td>
		<td width='200px'>Действия</td>
	</tr><?php
		$users = $db->getTable("select * from `users` order by `login`");
		foreach($users as $User)
		{
			echo "<tr><td>$User[user_id]</td>";
			echo "<td>$User[login]</td>";
			echo "<td>";
				switch ($User['type']){
					case "administrator": echo "Администратор"; break;
					case "manager": echo "Менеджер"; break;
					case "agent": echo "Агент"; break;
					default: echo $User['type'];
				}
			echo "</td>";
			echo "<td>$User[last_ip]</td>";
			echo "<td>".date("d.m.Y H:i",$User['last_time'])."</td>";
			if ($user->getUserId() == 1)
				echo "<td><a href='users/edit/$User[user_id]' class='edit'>Редактировать</a> | <a href='users/delete/$User[user_id]' class='delete'>Удалить</a></td></tr>";
			elseif ($user->getUserId() == $User['user_id'])
				echo "<td><a href='users/edit/$User[user_id]' class='edit'>Редактировать</a></td></tr>";
			else
				echo "<td></td></tr>";
		}
?></table>

<?php loadPage("footer.php"); ?>